package com.info.zhiduoduo.weixin.controller;

import com.info.zhiduoduo.common.annotation.LogEntity;
import com.info.zhiduoduo.common.annotation.ZddLog;
import com.info.zhiduoduo.common.constants.SmartResult;
import com.info.zhiduoduo.common.constants.system.ZddLogType;
import com.info.zhiduoduo.common.formbean.BaseSimpleFormBean;
import com.info.zhiduoduo.core.dto.taxer.TaxerInvoiceServiceChargeDto;
import com.info.zhiduoduo.repository.dto.taxer.TaxerCompanyDto;
import com.info.zhiduoduo.repository.dto.taxer.TaxerInvoiceDto;
import com.info.zhiduoduo.weixin.formbean.project.ProjectIdFormBean;
import com.info.zhiduoduo.weixin.formbean.taxer.*;
import com.info.zhiduoduo.weixin.service.TaxerService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = " 接口")
@RestController
@RequestMapping("/taxer")
public class TaxerController {

	@Autowired
	TaxerService taxerService;

/*	@ApiOperation(value = "注册(绑定手机号)", tags = "个人")
	@PostMapping("/v1/register")
	public ReturnValue register(@RequestBody BaseSimpleFormBean<RegFormBean> formBean) {
		return taxerService.register(formBean);
	}

	@ApiOperation(value = "获取 信息", tags = "个人")
	@PostMapping("/v1/getTaxerInfo")
	public ReturnValue<TaxerDetailDto> getTaxerInfo(@RequestBody BaseAuthInfo baseAuthInfo) {
		return taxerService.getTaxerInfo(baseAuthInfo);
	}

	@ApiOperation(value = "实名认证", tags = "个人")
	@PostMapping("/v1/realNameAuth")
	public ReturnValue realName(@RequestBody BaseSimpleFormBean<RealNameAuthFormBean> baseSimpleFormBean) {
		return taxerService.updateRealName(baseSimpleFormBean);
	}*/

	//******************************** 开票申请 ***************************

	@ApiOperation(value = "申请开票", notes = "返回object ： invoiceid", tags = " 发票")
	@PostMapping("/applyInovice")
	public SmartResult applyInvoice(@Valid @RequestBody BaseSimpleFormBean<ApplyInvoiceFormBean> formBean) {
		return taxerService.applyInvoice(formBean);
	}

	@ApiOperation(value = "获取 收藏的企业列表", tags = " 发票")
	@PostMapping("/companyList")
	public SmartResult<TaxerCompanyDto> getTaxerCompanyList(@RequestBody BaseSimpleFormBean<TaxerCompanyListFormBean> formBean) {
		return taxerService.getCompanyList(formBean);
	}

	@Deprecated
	@ApiOperation(value = "计算发票的服务费（含税费）", notes = "reqdata 传invoiceid", tags = " 发票")
	@PostMapping("/invoiceServiceCharge")
	public SmartResult<TaxerInvoiceServiceChargeDto> getInvoiceServiceCharge(@RequestBody BaseSimpleFormBean<Integer> formBean) {
		return taxerService.getInvoiceServiceCharge(formBean);
	}

	@ApiOperation(value = "计算税费, 使用阶梯税率", notes = "reqdata 传invoiceid", tags = " 发票")
	@PostMapping("/invoiceServiceChargeV2")
	public SmartResult<TaxerInvoiceServiceChargeDto> getInvoiceServiceChargeV2(@RequestBody BaseSimpleFormBean<Integer> formBean) {
		return taxerService.getInvoiceServiceChargeV2(formBean);
	}

	@ApiOperation(value = "获取我的发票列表", tags = " 发票")
	@PostMapping("/invoiceList")
	public SmartResult<TaxerInvoiceDto> getInvoiceList(@RequestBody BaseSimpleFormBean<InvoiceListFormBean> formBean) {
		return taxerService.getInvoiceList(formBean);
	}

	@ApiOperation(value = "获取发票详情", notes = "reqdata 传invoiceid", tags = " 发票")
	@PostMapping("/invoiceDetail")
	public SmartResult getInvoiceDetail(@RequestBody BaseSimpleFormBean<Integer> formBean) {
		return taxerService.getInvoiceDetail(formBean);
	}

	@ZddLog(type = ZddLogType.UPDATE,name = "编辑发票")
	@ApiOperation(value = "编辑发票", tags = " 发票")
	@PostMapping("/editInvoice")
	public SmartResult editInvoice(@RequestBody BaseSimpleFormBean<EditTaxerInvoiceFormBean> formBean) {
		return taxerService.editInovice(formBean);
	}

	@ZddLog(type = ZddLogType.DELETE,name = "删除发票")
	@ApiOperation(value = "删除发票", notes = "reqdata: invoiceid", tags = " 发票")
	@PostMapping("/delInvoice")
	public SmartResult delInvoice(@RequestBody BaseSimpleFormBean<Integer> formBean) {
		return taxerService.delInvoice(formBean);
	}

	@ApiOperation(value = "发票项目信息列表", notes = "reqdata: 搜索项目名", tags = " 发票")
	@PostMapping("/invoiceProjectList")
	public SmartResult getInvoiceProjectList(@RequestBody BaseSimpleFormBean<String> formBean) {
		return taxerService.getInvoiceProjectList(formBean);
	}

	@ApiOperation(value = "添加编辑发票项目", notes = "projectid 传0表示新增，大于0则编辑", tags = " 发票")
	@PostMapping("/addEditInvoiceProject")
	public SmartResult addEditInvoiceProject(@Valid @RequestBody BaseSimpleFormBean<AddEditInvoiceProjectFormBean> formBean) {
		return taxerService.addEditInvoiceProject(formBean);
	}

	@ApiOperation(value = "删除发票项目", notes = "reqdata传项目id", tags = " 发票")
	@PostMapping("/delInvoiceProject")
	public SmartResult delInvoiceProject(@RequestBody BaseSimpleFormBean<Integer> formBean) {
		return taxerService.delInvoiceProject(formBean);
	}

	@ApiOperation(value = "将发票合同发到邮箱", tags = " 发票")
	@PostMapping("/sendContractEmail")
	public SmartResult sendContractEmail(@Valid @RequestBody BaseSimpleFormBean<InvoiceEmailFormBean> formBean) {
		return taxerService.sendContractEmail(formBean);
	}

	@ApiOperation("将项目合同发到邮箱(PDF文件)")
	@PostMapping("/sendPdfContractEmail")
	public SmartResult sendPdfContractEmail(@Valid @RequestBody BaseSimpleFormBean<InvoiceEmailFormBean> formBean) {
		return taxerService.sendPdfContractEmail(formBean);
	}

	//******************************** 收藏企业***************************

	@ApiOperation(value = "编辑收藏的企业", notes = "返回companyid", tags = " 企业")
	@PostMapping("/editCompany")
	public SmartResult editCompany(@Valid @RequestBody BaseSimpleFormBean<EditTaxerCompanyFormBean> formBean) {
		return taxerService.editCompany(formBean);
	}

	@ApiOperation(value = "删除收藏的企业", notes = "reqdata 传 companyid", tags = " 企业")
	@PostMapping("/delCompany")
	public SmartResult delCompany(@RequestBody BaseSimpleFormBean<Integer> formBean) {
		return taxerService.delCompany(formBean);
	}

	@ApiOperation(value = "获取收藏企业详情", notes = "收藏企业列表点开票时获取详情", tags = " 企业")
	@PostMapping("/companyInfo")
	public SmartResult<TaxerCompanyDto> getTaxerCompanyInfo(@RequestBody BaseSimpleFormBean<Integer> formBean) {
		return taxerService.getTaxerCompanyInfo(formBean);
	}

	@PostMapping("/generateInviteCode")
	public SmartResult generateInviteCode() {
		taxerService.generateInviteCode();
		return new SmartResult();
	}

	//******************************** 支付 ***************************

	@ZddLog(name = " 调用支付，使用微信支付")
	@ApiOperation(value = " 调用支付，使用微信支付", notes = " 支付类型 1：开户 2：续期 3：开票")
	@PostMapping("/submitPay")
	public SmartResult submitPay(@RequestBody BaseSimpleFormBean<TaxerSubmitWxpayFormBean> formBean, HttpServletRequest request) {
		return taxerService.submitPay(formBean, request);
	}

	@ApiOperation("获取 邀请码列表")
	@PostMapping("/inviteCodeList")
	public SmartResult getTaxerInviteCodeList(@RequestBody BaseSimpleFormBean<String> formBean) {
		return taxerService.getTaxerInviteCodeList(formBean);
	}

}
